using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using System.Xml.Serialization;

namespace Easy.Geo.Kml
{
    public class Link : Object
    {
        public Link() 
            : base() 
        {
            this._refreshMode = RefreshMode.OnChange;
            this._refreshInterval = 4;
            this._viewRefreshMode = ViewRefreshMode.Never;
            this._viewRefreshTime = 4;
            this._viewBoundScale = 1;
            this._viewFormat = "BBOX=[bboxWest],[bboxSouth],[bboxEast],[bboxNorth]";
        }
        public Link(string id) 
            : base(id) 
        {
            this._refreshMode = RefreshMode.OnChange;
            this._refreshInterval = 4;
            this._viewRefreshMode = ViewRefreshMode.Never ;
            this._viewRefreshTime = 4;
            this._viewBoundScale = 1;
            this._viewFormat = "BBOX=[bboxWest],[bboxSouth],[bboxEast],[bboxNorth]";            
        }
        public Link(string id, string href)
            : this(id)
        {
            this._href = href;
        }
        public Link(string id, string href, RefreshMode refreshMode, float refreshInterval, ViewRefreshMode viewRefreshMode,
            float viewRefreshTime, float viewBoundScale, string viewFormat, string httpQuery)
            : base(id)
        {
            this._href = href;
            this._refreshMode = refreshMode;
            this._refreshInterval = refreshInterval;
            this._viewRefreshMode = viewRefreshMode;
            this._viewRefreshTime = viewRefreshTime;
            this._viewBoundScale = viewBoundScale;
            this._viewFormat = viewFormat;
            this._httpQuery = httpQuery;
        }

        private string _href;
        [XmlElement(ElementName="href")]
        public string Href
        {
            get { return _href; }
            set { _href = value; }
        }
        private RefreshMode _refreshMode;
        [XmlElement(ElementName="refreshMode")]
        public RefreshMode RefreshMode
        {
            get { return _refreshMode; }
            set { _refreshMode = value; }
        }
        private float _refreshInterval;
        [XmlElement(ElementName="refreshInterval")]
        public float RefreshInterval
        {
            get { return _refreshInterval; }
            set { _refreshInterval = value; }
        }
        private ViewRefreshMode _viewRefreshMode;
        [XmlElement(ElementName = "viewRefreshMode")]
        public ViewRefreshMode ViewRefreshMode
        {
            get { return _viewRefreshMode; }
            set { _viewRefreshMode = value; }
        }
        private float _viewRefreshTime;
        [XmlElement(ElementName = "viewRefreshTime")]
        public float ViewRefreshTime
        {
            get { return _viewRefreshTime; }
            set { _viewRefreshTime = value; }
        }
        private float _viewBoundScale;
        [XmlElement(ElementName = "viewBoundScale")]
        public float ViewBoundScale
        {
            get { return _viewBoundScale; }
            set { _viewBoundScale = value; }
        }
        private string _viewFormat;
        [XmlElement(ElementName = "viewFormat")]
        public string ViewFormat
        {
            get { return _viewFormat; }
            set { _viewFormat = value; }
        }
        private string _httpQuery;
        [XmlIgnore()]
        public string HttpQuery
        {
            get { return _httpQuery; }
            set { _httpQuery = value; }
        }
        [XmlElement(ElementName = "httpQuery")]
        public XmlCDataSection XmlHttpQuery
        {
            get
            {
                XmlDataDocument doc = new XmlDataDocument();
                XmlCDataSection cdata = doc.CreateCDataSection(this._httpQuery);
                return cdata;
            }
            set
            {
                this._httpQuery = value.Value;
            }
        }
    }
}
